package com.qilin.hscs.hm.dao;


import com.qilin.hscs.hm.pojo.Device;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * Created by 10188 on 2018/3/24.
 */
@Repository
public interface DeviceRepository extends JpaRepository<Device,Integer> {

    @Query("select d.ieee as ieee,d.uid as uid ,d.roomId as roomId from Device d group by d.ieee")
    List<Map<String, Object>> findDistinctDevice();

    List<Device> findByIeee(String ieee);

    Device findByIeeeAndEp(String ieee, Integer ep);

    List<Device> findByEptIn(List<Integer> epts);

    @Modifying
    @Query("delete from Device d where d.ieee=?1")
    int  deleteByIeee(String ieee);

    List<Device> findByRoomId(int roomId);

    @Query("select d.ieee as ieee,d.uid as uid from Device d where d.roomId=?1 group by d.ieee")
    List<Map<String, String>> findIeeesByRoomId(int roomId);

    List<Device> findById(int id);

    Device findByIeeeAndEpAndUid(String ieee, Integer ep, String uid);

}
